﻿#pragma once
#include "df.h"

#if defined(_WIN32) || defined(_WIN32_WCE)

#include <winsock2.h>


#ifdef _MSC_VER 
#	if defined(_WIN32_WCE)
#		pragma comment( lib, "ws2.lib" )
#	else
#		pragma comment( lib, "Ws2_32" )
#	endif
#endif
#else
#	include <unistd.h>
#endif

namespace df
{
	inline bool initWSA()
	{
#if defined(_WIN32) || defined(_WIN32_WCE)
		static bool no = true;
		if (no)
		{
			WSADATA wsda;
			if (WSAStartup(MAKEWORD(2, 2), &wsda) != 0)
			{
				DF_ERR(tt_("WSAStartup failed"));
				return false;
			}
			no = false;
		}
#endif
		return true;
	}

	inline const char * getHostName()
	{
		initWSA();

		static TCHAR host[df::BUFFER_SIZE] = { 0 };
		if (host[0])
			return host;

		int res = gethostname(host, df::BUFFER_SIZE);
		return host;
	}
}